arch(lint): split layer0.go into focused sibling files - #678
Conversation
layer0.go at 1 203 lines packed seven sub-parsers into one file, making targeted changes risky and the file hard to navigate. Split into three focused siblings within the same package: - layer0_html.go: HTML-block detection (types 1–7), openHTMLBlock, htmlBlockCloses, tagName, and related helpers - layer0_fence.go: fenceInfo, openingFence, closingFence, advanceFenceState, tryFence - layer0_para.go: scanParagraph, markSetextRun, paragraphLeadKind, SourceMayHaveCodeBlock, blockquote helpers (blockDepth, isLazyContinuation, lineHasNonFenceCode, stripQuoteMarker), and list/setext/thematic-break predicates layer0.go now holds only the exported types, scanner state machine, and PI/ATX/indented-code sub-parsers (533 lines, down from 1 203). Pure file reorganisation — no logic changes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137dbEGzRTJcTDpCh3QuEFu
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
gofmt requires no trailing newline after the final closing brace. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137dbEGzRTJcTDpCh3QuEFu
…Block HTML block type detection (types 2–5) used regexps to match fixed string prefixes (<!--, <?, <![A-Za-z], <![CDATA[). After the angle-bracket gate already confirms indent≤3 and line[indent]=='<', these reduce to bytes.HasPrefix / direct byte comparisons, eliminating 4 package-level regexp vars and firstNonSpaceIsAngle. Also replaces bytes.Contains with single-byte needle (htmlClose4) with bytes.IndexByte for the type-4 close check, removing the htmlClose4 var. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137dbEGzRTJcTDpCh3QuEFu
The two slices were grown from nil via repeated append, triggering geometric re-allocations for large block quotes. Pre-size to len(s.lines)-s.i (an upper bound on lines the quote can consume) to eliminate all intermediate re-allocations, per the project's pre-size-with-make rule. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137dbEGzRTJcTDpCh3QuEFu
isLazyContinuation checked fences, PIs, and HTML blocks but not ATX headings. A bare '# heading' line (no > prefix) inside a block quote was absorbed as a lazy continuation, extending the BlockQuote.End span past the heading. Per CommonMark §5.1, ATX headings interrupt lazy continuation. Also correct the openHTMLBlock comment: 'skip all RE2 executions' was inaccurate (type-1 lines still run htmlType1Open.Match); now reads 'skip the regexp battery entirely'. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137dbEGzRTJcTDpCh3QuEFu
|
🟢 Merge Queue — picked up This PR is in the queue and will be batched with other Next: No action needed — you'll get another comment when CI starts on the batch. View merge queue run. |
|
🔵 Merge Queue — CI running Merged into batch branch Next: No action needed — you'll be notified when CI completes. |
|
✅ Merge Queue — merged This PR landed on Next: Done — nothing more to do here. |
Summary
internal/lint/layer0.gowas 1 203 lines, packing seven sub-parsers into one file and making targeted changes riskylintpackage (no import changes needed by callers):layer0_html.go: HTML-block detection (types 1–7),openHTMLBlock,htmlBlockCloses,tagName, and related helpers (240 lines)layer0_fence.go:fenceInfo,openingFence,closingFence,advanceFenceState,tryFence(148 lines)layer0_para.go:scanParagraph,markSetextRun,paragraphLeadKind,SourceMayHaveCodeBlock, block-quote helpers (blockDepth,isLazyContinuation,lineHasNonFenceCode,stripQuoteMarker), and list/setext/thematic-break predicates (292 lines)layer0.gonow holds exported types, the scanner state machine, and PI/ATX/indented-code sub-parsers — 533 lines, down from 1 203Test plan
go build ./...passesgo test ./...passes (all packages green)go run ./cmd/mdsmith check .passes (508 files, 0 failures)wc -l internal/lint/layer0.goreports 533 (under 600)go tool -modfile=tools/go.mod golangci-lint run— requires Go 1.25.8+; environment has 1.25.0, CI will verify🤖 Generated with Claude Code
https://claude.ai/code/session_0137dbEGzRTJcTDpCh3QuEFu
Generated by Claude Code